<!--
 * @FilePath     : /study_code/vue2.x/component-extend.html
 * @Description  : Vue.extend() 继承组件
 * @Date         : 2025-05-02 19:06:20
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-02 19:06:20
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="app">
      <my-component1></my-component1>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="./common.js"></script>
    <script>
      // 1 自定义组件
      const msg = {
        data: function () {
          return {
            title: '!!title变量的内容!!',
          }
        },
        props: [],
        template: `
          <div>
            <h2>这里是 msg</h2>
            {{ title }}
          </div>`,
        methods: {
          run() {
            return 1 + 3
          },
        },
      }

      const myComponent1 = {
        components: {
          msg,
        },
        extends: msg, // 这里使用 extend 配置项继承 msg 组件
        data: function () {
          return {}
        },
        props: [],
        template: `
          <div>
            <h2>这里是 c1</h2>
            <msg></msg>
            <h4>子组件内使用 extends 来变量 --- {{ title }}</h4>
          </div>
          `,
        created() {
          console.log('运行 extends 来的方法', this.run())
        },
        methods: {},
      }

      var app = new Vue({
        el: '#app',
        data: function () {
          return {}
        },
        components: {
          myComponent1,
        },
      })
    </script>
  </body>
</html>
